$(function() {
	{if $item.area_id}
	console.log({$item.area_id})
	for(var areaidx=0;areaidx<$('.area').find('option').length;areaidx++){
		$('.area').find('option').eq(areaidx).attr('selected', false);
	}
	$('.area').find('option').eq({$item.area_id-1}).attr('selected', true);
	{/if}
	{if $item.car_model_id}
	{else/}
		var brandid=$('.brand select').val();

		$.ajax({
			method: "POST",
			url:"{:url('car/brands')}",
			data:{
				id:brandid
			},
			success:function(res){
				console.log(res);
					$('.model select').html(res);
			}
		});
	{/if}
	//图片上传显示

	$('.keep').on('click', function() {
		var treeObj = $.fn.zTree.getZTreeObj("ztreeid");
		var nodes = treeObj.getNodes();
		console.log(nodes);
		var text = [];
		for(var i = 0; i < nodes.length; i++) {
		if(nodes[i].checked) {text.push(nodes[i].id)}
			if(nodes[i].children) {
				for(var j = 0; j < nodes[i].children.length; j++) {
					if(nodes[i].children[j].checked) {text.push(nodes[i].children[j].id)}
					if(nodes[i].children[j].children) {
						for(var z = 0; z < nodes[i].children[j].children.length; z++) {
							if(nodes[i].children[j].children[z].checked) {text.push(nodes[i].children[j].children[z].id)}
						}
					}
				}
			}
		}

		$('.prop').val(text)
		console.log($('.prop').val())
		{if $Think.get.remote}
		sendForm($(this), 1,'{:url("/admin/custom/car")}');
		{else/}
		{if $item.number}
		sendForm($(this), 1,window.location.href);
		{else/}
		sendForm($(this), 1,'{:url("index")}');
		{/if}
		{/if}
	});
	$('.back').on('click', function() {
		window.history.back();
	});
	$('.car_type').on('click', function() {
		choosecar("{:url('models/index',['op'=>'search'])}");
	});
	$('.company_name').on('click', function() {
		choosecar("{:url('company/index',['op'=>'search'])}?own=1&entrust=0");
	});
	$('.entrust_company_name').on('click', function() {
		choosecar("{:url('company/index',['op'=>'search'])}?own=9&entrust=1");
	});
	$('.car_use').on('click', function() {
		choosecar("{:url('company/index',['op'=>'search'])}");
	});
//	$('.car_entrust').on('click', function() {
//		console.log($('.ziyou').val())
//		if($('.ziyou').val()==1){
//			choosecar("{:url('company/index',['op'=>'entrust'])}?own=1")
//		}else{
//			choosecar("{:url('company/index',['op'=>'entrust'])}?own=9")
//		}
//		
//	});
	$('.register').on('click',function(){
		Msg('登记成功')
		window.location.href='{:url("audit")}';
	})
	$('.register_back').on('click',function(){
		window.location.href='{:url("audit")}';
	})

	$('.ziyou').on('change',function(){
		// $('.company_id').val("");
		// $('.company_name').val("");
		if($(this).val()==1){
			$('.entrust_company').css('display','none');

			//$('.entrust_company_id').removeAttr('name')
            $('.entrust_company_id').val('');
            $('.entrust_company_name').val('');
		}else{
			$('.entrust_company').css('display','block');
			//$('.entrust_company_id').attr('name','entrust_company_id')
		}
	})
	//选择品牌

	$('.brand select').on('change',function(){
		var brandid=$(this).val();
		var brand = layer.load(1, {
		  shade: [0.1,'#fff'] //0.1透明度的白色背景
		});
		$.ajax({
			method: "POST",
			url:"{:url('car/brands')}",
			data:{
				id:brandid
			},
			success:function(res){
				console.log(res);
				  layer.close(brand);
					$('.model select').html(res);
			}
		});
	})
	$('.model select').on('change',function(){
		var model = layer.load(1, {
		  shade: [0.1,'#fff'] //0.1透明度的白色背景
		});
		var modelid=$(this).val();
		console.log(modelid)
		if(modelid){
		$.ajax({
			method: "POST",
			url:"{:url('car/brands')}",
			data:{
				id:modelid
			},
			success:function(res){
				 $('.series select').html(res)
			}
		});
		}else{
			$('.series select').html('')
		}
		layer.close(model);
	})
	$('.buy_date').on('change',function(){
		var newdata=new Date()
		var buydata=new Date($(this).val())
		var year=Math.ceil((newdata-buydata)/1000/3600/24/365)
		$('.car_age').val(year)
	})
	{if $props}
	var setting = {
		check: {
			enable: true,
			chkDisabledInherit: true,
			chkStyle: "radio"
		},
		data: {
			simpleData: {
				enable: true
			}
		}
	};
	var zNodes = {$props};
	$.fn.zTree.init($("#ztreeid"), setting, zNodes);
	{/if}

})